import * as Cesium from 'cesium';
const { WebGLConstants, PixelDatatype } = Cesium;
let { PixelFormat } = Cesium
export const PixelFormatGaussianSplatting = {
    ...PixelFormat,
    RED_INTEGER: WebGLConstants.RED_INTEGER,
    RG_INTEGER: WebGLConstants.RG_INTEGER,
    RGB_INTEGER: WebGLConstants.RGB_INTEGER,
    RGBA_INTEGER: WebGLConstants.RGBA_INTEGER,
    componentsLength: function (pixelFormat: any) {
        switch (pixelFormat) {
            case PixelFormatGaussianSplatting.RGB:
            //@ts-ignore
            case PixelFormatGaussianSplatting.RGB_INTEGER:
                return 3;
            case PixelFormatGaussianSplatting.RGBA:
            //@ts-ignore
            case PixelFormatGaussianSplatting.RGBA_INTEGER:
                return 4;
            case PixelFormatGaussianSplatting.LUMINANCE_ALPHA:
            case PixelFormatGaussianSplatting.RG:
            //@ts-ignore
            case PixelFormatGaussianSplatting.RG_INTEGER:
                return 2;
            case PixelFormatGaussianSplatting.ALPHA:
            case PixelFormatGaussianSplatting.RED:
            //@ts-ignore
            case PixelFormatGaussianSplatting.RED_INTEGER:
            case PixelFormatGaussianSplatting.LUMINANCE:
                return 1;
            default:
                return 1;
        }
    },
    validate: function (pixelFormat: any) {
        return (
            pixelFormat === PixelFormatGaussianSplatting.DEPTH_COMPONENT ||
            pixelFormat === PixelFormatGaussianSplatting.DEPTH_STENCIL ||
            pixelFormat === PixelFormatGaussianSplatting.ALPHA ||
            pixelFormat === PixelFormatGaussianSplatting.RED ||
            pixelFormat === PixelFormatGaussianSplatting.RG ||
            pixelFormat === PixelFormatGaussianSplatting.RGB ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA ||
            //@ts-ignore
            pixelFormat === PixelFormatGaussianSplatting.RED_INTEGER ||
            //@ts-ignore
            pixelFormat === PixelFormatGaussianSplatting.RG_INTEGER ||
            //@ts-ignore
            pixelFormat === PixelFormatGaussianSplatting.RGB_INTEGER ||
            //@ts-ignore
            pixelFormat === PixelFormatGaussianSplatting.RGBA_INTEGER ||
            pixelFormat === PixelFormatGaussianSplatting.LUMINANCE ||
            pixelFormat === PixelFormatGaussianSplatting.LUMINANCE_ALPHA ||
            pixelFormat === PixelFormatGaussianSplatting.RGB_DXT1 ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA_DXT1 ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA_DXT3 ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA_DXT5 ||
            pixelFormat === PixelFormatGaussianSplatting.RGB_PVRTC_4BPPV1 ||
            pixelFormat === PixelFormatGaussianSplatting.RGB_PVRTC_2BPPV1 ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA_PVRTC_4BPPV1 ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA_PVRTC_2BPPV1 ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA_ASTC ||
            pixelFormat === PixelFormatGaussianSplatting.RGB_ETC1 ||
            pixelFormat === PixelFormatGaussianSplatting.RGB8_ETC2 ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA8_ETC2_EAC ||
            pixelFormat === PixelFormatGaussianSplatting.RGBA_BC7
        );
    },
    toInternalFormat: function (pixelFormat: any, pixelDatatype: any, context: any) {
        // WebGL 1 require internalFormat to be the same as PixelFormat
        if (!context.webgl2) {
            return pixelFormat;
        }

        // Convert pixelFormat to correct internalFormat for WebGL 2
        if (pixelFormat === PixelFormatGaussianSplatting.DEPTH_STENCIL) {
            return WebGLConstants.DEPTH24_STENCIL8;
        }

        if (pixelFormat === PixelFormatGaussianSplatting.DEPTH_COMPONENT) {
            if (pixelDatatype === PixelDatatype.UNSIGNED_SHORT) {
                return WebGLConstants.DEPTH_COMPONENT16;
            } else if (pixelDatatype === PixelDatatype.UNSIGNED_INT) {
                return WebGLConstants.DEPTH_COMPONENT24;
            }
        }

        if (pixelDatatype === PixelDatatype.FLOAT) {
            switch (pixelFormat) {
                case PixelFormatGaussianSplatting.RGBA:
                    return WebGLConstants.RGBA32F;
                case PixelFormatGaussianSplatting.RGB:
                    return WebGLConstants.RGB32F;
                case PixelFormatGaussianSplatting.RG:
                    return WebGLConstants.RG32F;
                case PixelFormatGaussianSplatting.RED:
                    return WebGLConstants.R32F;
            }
        }

        if (pixelDatatype === PixelDatatype.HALF_FLOAT) {
            switch (pixelFormat) {
                case PixelFormatGaussianSplatting.RGBA:
                    return WebGLConstants.RGBA16F;
                case PixelFormatGaussianSplatting.RGB:
                    return WebGLConstants.RGB16F;
                case PixelFormatGaussianSplatting.RG:
                    return WebGLConstants.RG16F;
                case PixelFormatGaussianSplatting.RED:
                    return WebGLConstants.R16F;
            }
        }
        //@ts-ignore
        if (pixelDatatype === PixelDatatype.INT) {
            switch (pixelFormat) {
                //@ts-ignore
                case PixelFormatGaussianSplatting.RGBA_INTEGER:
                    return WebGLConstants.RGBA32I;
                //@ts-ignore
                case PixelFormatGaussianSplatting.RGB_INTEGER:
                    return WebGLConstants.RGB32I;
                //@ts-ignore
                case PixelFormatGaussianSplatting.RG_INTEGER:
                    return WebGLConstants.RG32I;
                //@ts-ignore
                case PixelFormatGaussianSplatting.RED_INTEGER:
                    return WebGLConstants.R32I;
            }
        }

        if (pixelDatatype === PixelDatatype.UNSIGNED_INT) {
            switch (pixelFormat) {
                //@ts-ignore
                case PixelFormatGaussianSplatting.RGBA_INTEGER:
                    return WebGLConstants.RGBA32UI;
                //@ts-ignore
                case PixelFormatGaussianSplatting.RGB_INTEGER:
                    return WebGLConstants.RGB32UI;
                //@ts-ignore
                case PixelFormatGaussianSplatting.RG_INTEGER:
                    return WebGLConstants.RG32UI;
                //@ts-ignore
                case PixelFormatGaussianSplatting.RED_INTEGER:
                    return WebGLConstants.R32UI;
            }
        }

        return pixelFormat;
    }
} as { [xx: string | symbol]: any }